#include<bits/stdc++.h>
using namespace std;
const int N=10000005;
int T;
bool vis[N],b[N];
int n,m,L,V;
long long ans1,ans2;
long long d[N],v[N],a[N],p[N],l[N],r[N],f[N];
int lowbit(int x){
    return x&-x;
}
void add(int x,int k){
    while(x<=L){
        f[x]+=k;
        x+=lowbit(x);
    }
}
long long sum(int x){
    long long ans=0;
    while(x>0){
        ans+=f[x];
        x-=lowbit(x);
    }
    return ans;
}
void dfs(int u,long long t,bool f1){
    if(u>m){
        ans2=min(ans2,t);
        return ;
    }
    add(p[u],-1);
    bool f=false;
    for(int i=1;i<=n;i++){
        if(!b[i])continue;
        if(sum(r[i])-sum(l[i]-1)==0){
            f=true;
            break;
        }
    }
    if(!f){
        dfs(u+1,t,0);
    }
    add(p[u],1);
    dfs(u+1,t+1,1);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n>>m>>L>>V;
        memset(f,0,sizeof(f));
        memset(vis,0,sizeof(vis));
        memset(b,0,sizeof(b));
        ans1=0;
        ans2=INT_MAX;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
            if(a[i]<0){
                if(v[i]<V){
                    vis[i]=true;
                    continue;
                }
                double x;
                x=1.0*(v[i]*v[i]-V*V)/(2*1.0*abs(a[i]));
                l[i]=d[i];
                r[i]=min(L,int(ceil(x+d[i]-1)));
            }else if(a[i]>0){
                if(v[i]>V){
                    l[i]=d[i];
                    r[i]=L;
                }else if(v[i]==V){
                    l[i]=d[i]+1;
                    r[i]=L;
                }else{
                    double x;
                    x=(V*V-v[i]*v[i])*1.0/(2*a[i]*1.0);
                    l[i]=int(floor(1+x+d[i]));
                    r[i]=L;
                }
            }else{
                if(v[i]<=V){
                    vis[i]=true;
                    continue;
                }
                l[i]=d[i];
                r[i]=L;
            }
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];
            add(p[i],1);
        }
        for(int i=1;i<=n;i++){
            if(vis[i])continue;
            if(r[i]<l[i])continue;
            if(sum(r[i])-sum(l[i]-1)>0){
                ans1++;
                b[i]=true;
            }
        }
        dfs(1,0,0);
        cout<<ans1<<" "<<m-ans2<<'\n';
    }
    return 0;
}
